<?php
include("../../inc/global.inc");
include("../islogin.php");
?>
<?php
//---------------------------------------------------------
//财付通即时到帐支付应答（处理回调）示例，商户按照此文档进行开发即可
//---------------------------------------------------------
require_once ("./classes/PayResponseHandler.class.php");
/* 密钥 */
$key = "sxk72faye660077kangjiaaolin7766m";
/* 创建支付应答对象 */
$resHandler = new PayResponseHandler();
$resHandler->setKey($key);
//判断签名
if($resHandler->isTenpaySign()) {
	
	//交易单号
	$transaction_id = $resHandler->getParameter("transaction_id");
	
	//金额,以分为单位
	$total_fee = $resHandler->getParameter("total_fee");
	$price=($total_fee/100);
	
	//支付结果
	$pay_result = $resHandler->getParameter("pay_result");
		
	if("0" == $pay_result) {
	$rs=@mysql_query("select * from member where transaction_id='$transaction_id'");
		$row=@mysql_fetch_array($rs);
		if($row['id']){
		   $jifen=$row[m_jifen]+$price;
		  // echo $jifen."<br>";
		   //echo $row[m_jifen];
		   mysql_query("update member set m_jifen='$jifen',transaction_id='' where id='".$row['id']."'");
		   mysql_query("insert into jifen (member_id,j_type,j_num,j_name,add_time,transaction_id) values ('".$row['id']."','2','$price','财付通充值','".date("Y-m-d H:i:s")."','$transaction_id')");
		
		}
		//------------------------------
		//处理业务开始
		//------------------------------
		
		//注意交易单不要重复处理
		//注意判断返回金额
		
		//------------------------------
		//处理业务完毕
		//------------------------------	
		
		//调用doShow, 打印meta值跟js代码,告诉财付通处理成功,并在用户浏览器显示$show页面.
		$show = "http://www.sandib2b.cn/per-mb/show.php";
		$resHandler->doShow($show);
	} else {
		//当做不成功处理
		echo "<br/>" . "支付失败" . "<br/>";
	}
	
} else {
	echo "<br/>" . "认证签名失败" . "<br/>";
}

//echo $resHandler->getDebugInfo();

?>